import javax.swing.tree.TreeNode;
//数据结构复习——二叉树
public class Code {
    //
}


//public TreeNode createTree(){
//    TreeNode A = new TreeNode('A');
//    TreeNode B = new TreeNode('B');
//    TreeNode C = new TreeNode('C');
//    TreeNode D = new TreeNode('D');
//    TreeNode E = new TreeNode('E');
//    TreeNode F = new TreeNode('F');
//    TreeNode G = new TreeNode('G');
//    TreeNode H = new TreeNode('H');
//    A.left = B;
//    A.right = C;
//    B.left = D;
//    B.right = E;
//    C.left = F;
//    C.right = G;
//    E.right = H;
//    return A;
//}


//定义一个二叉树
class BinaryTree {
    private DataTree root;

    public void setRoot(DataTree root) {
        this.root = root;
    }

    public DataTree getRoot() {
        return root;
    }

    //前序遍历
    public void preOrder(DataTree tree) {
        if (tree == null)
            return;
        System.out.println(tree);
        //遍历左子树
        preOrder(tree.getLeft());
        //遍历右子树
        preOrder(tree.getRight());


    }

    //中序遍历
    public void infixOrder(DataTree tree) {
        if (tree == null)
            return;

        //遍历左子树
        infixOrder(tree.getLeft());
        //打印
        System.out.println(tree);
        //遍历右子树
        infixOrder(tree.getRight());


    }

    //后序遍历
    public void postOrder(DataTree tree) {
        if (tree == null)
            return;

        //遍历左子树
        postOrder(tree.getLeft());
        //遍历右子树
        postOrder(tree.getRight());
        //打印

        System.out.println(tree);


    }


}

//先创建结点
class DataTree {
    private int num;
    private DataTree left;
    private DataTree right;

    public void setNum(int num) {
        this.num = num;
    }

    public int getNum() {
        return num;
    }

    public DataTree getLeft() {
        return left;
    }

    public void setLeft(DataTree left) {
        this.left = left;
    }

    public DataTree getRight() {
        return right;
    }

    public void setRight(DataTree right) {
        this.right = right;
    }

    public DataTree(int num) {
        this.num = num;
    }

    @Override
    public String toString() {
        return "DataTree{" +
                "num=" + num +
                '}';
    }

}